/**
 * 打印
 * @param {HTMLElement} ele 页面上要打印的元素
 * @param {Object} option // 打印参数
 */
export const printjs = function(ele, option = {}) {
    let targetELe = ele;
    if (ele === undefined) {
        targetELe = document.body;
    }
    const opt = Object.assign(
        Object.create(null),
        {
            title: "",
            style: "",
        },
        option
    );
    const header = `<html><head><title>${opt.title}</title><style>@media print {${opt.style}}</style></head><body>`;
    const footer = `</body></html>`;
    const body = targetELe.innerHTML;
    const frame = document.createElement("IFRAME");
    frame.style.display = "none";
    const html = [header, body, footer].join("");
    frame.srcdoc = html;
    document.body.appendChild(frame);
    frame.contentWindow.focus();
    frame.contentWindow.print();
    const timer = setTimeout(() => {
        document.body.removeChild(frame);
        clearTimeout(timer);
    }, 1000);
};
